package ru.tapublog.lib.samsungwallet.impl.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import ru.tapublog.lib.samsungwallet.impl.dao.DateType;

public class DateConverter {
	// FEB 25 2013 03:10 PM
	public static final String DATE_FORMAT = "MMM dd yyyy hh:mm aa";

	public static String convertDate(Date date) {
		return convertDate(date, DATE_FORMAT);
	}

	public static DateType convertDateType(Date date, String format) {
		if (date == null)
			return null;
		DateType dType = new DateType();
		dType.setFormat(format);
		dType.setValue(convertDate(date, format));
		return dType;
	}

	public static DateType convertDateType(Date date) {
		return convertDateType(date, DATE_FORMAT);
	}

	public static String convertDate(Date date, String format) {
		SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US);
		formatter.setTimeZone(TimeZone.getTimeZone("UTC+0"));
		return formatter.format(date);
	}

	public static Date convertDate(String value) throws ParseException {
		return convertDate(value, DATE_FORMAT);
	}

	public static Date convertDate(String date, String format)
			throws ParseException {
		SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US);
		// format.setTimeZone(TimeZone.getTimeZone("UTC+0"));
		return formatter.parse(date);
	}
}
